package com.example.controllor;

import com.example.common.Result;
import com.example.entity.Shoucang;
import com.example.service.ShoucangService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shoucang")
public class ShoucangControllor {

    @Resource
    ShoucangService shoucangService;
    @PostMapping("/add")
    public Result add(@RequestBody Shoucang shoucang){
        shoucangService.add(shoucang);
        return Result.success();
    }
    @PostMapping("/delete")
    public Result delete(@RequestBody Shoucang shoucang){
        shoucangService.delete(shoucang);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Shoucang shoucang){
        shoucangService.update(shoucang);
        return Result.success();
    }

    @GetMapping("/selectAll")
    public Result selectAll(Shoucang shoucang){
        List<Shoucang> shoucangList = shoucangService.selectAll(shoucang);
        return Result.success(shoucangList);
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             Shoucang shoucang){
        PageInfo<Shoucang> pageInfo = shoucangService.selectPage(pageNum, pageSize, shoucang);
        return Result.success(pageInfo);
    }
}
